package com.example.mydesignmodule.flyweight;

import java.util.HashMap;

/**
 * @author tgw
 * @date 2021/3/11
 * @describe
 */
class FactoryBuyTicket {

    static HashMap<String, FlyweightTicket> ticketHashMap = new HashMap<>();

    public static FlyweightTicket getTicket(String from, String to) {
        String totalAddress = from + "-" + to;
        if (ticketHashMap.containsKey(totalAddress)) {
            FlyweightTicket ticket = ticketHashMap.get(totalAddress);
            return ticket;
        } else {
            FlyweightTicket ticket = new BuyTicket(from, to);
            ticketHashMap.put(totalAddress, ticket);
            return ticket;
        }
    }


}
